package edu.ciee.tz.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import edu.ciee.tz.model.Pbhou;

@Component("pbhouDao")
public class PbhouDAO {

	public List<Pbhou> search(Pbhou p) throws Exception {

		String query = "where 1=1";

		if (p.getId() != 0) 
			query = query + " and id like '%" + p.getId() + "%'";// this.getID()
		if (p.getPbhou_time() != null) 
			query = query + " and pbhou_time like '%" + p.getPbhou_time() + "%'"; // this.getName()
		if (p.getBg_num()!= 0) 
			query = query + " and bg_num like '%" + p.getBg_num() + "%'"; // this.getName()
		if (p.getEd_num()!= 0) 
			query = query + " and ed_num like '%" + p.getEd_num() + "%'"; // this.getName()
		if(p.getFz_person()!=null&&p.getFz_person().getId()!= 0) 
			query = query + " and fz_person like '%" + p.getFz_person().getName()+ "%'"; // this.getName()
		
		@SuppressWarnings("unchecked")
		List<Pbhou> p_list = hibernateTemplate.find("from Pbhou u "+ query);

		return p_list;
	}

	public void insert(Pbhou l) throws Exception {
		this.getHibernateTemplate().save(l);
	}

	public void delete(Pbhou l) throws Exception {
		this.getHibernateTemplate().delete(l);

	}

	public void update(Pbhou l) throws Exception {
		this.getHibernateTemplate().update(l);
	}

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
